const app = getApp();
Page({
    data: {
        newsPasswordShow:false,
        newsPasswordShow2:false,
        findPasswordPhoneVal:'',
        findPasswordCaptchaVal:'',
        findPasswordNewVal:'',
        findConfirmNewPasswordVal:'',
        codeBool:true,
        time:60*1000,
    },
    onLoad: function (options) {

    },
    passwordShowChange(){
        this.setData({
            newsPasswordShow:!this.data.newsPasswordShow
        })
    },

    passwordShowCon(){
        this.setData({
            newsPasswordShow2:!this.data.newsPasswordShow2
        })
    },

    finish(){
        this.setData({
            codeBool:true
        })
    },

    // 获取验证码
    phoneCaptchaBtn:function(){
        var { findPasswordPhoneVal ,codeBool} = this.data
        if (!findPasswordPhoneVal || !codeBool){
            return false
        }
        wx.showLoading({
            title: '加载中',
        })
        var url = app.globalData.baseUrl + 'user/sendCode';
        var data = {
            phone: findPasswordPhoneVal,
            type: 2
        }
        app.wxGetRequest(url, data, (res) => {
            console.log(res)
            wx.hideLoading()
            if (res.code == 1000) {
                wx.showToast({
                    title: '发送成功',
                    icon: 'success',
                    duration: 2000
                })
                this.setData({
                    codeBool:false
                })
            }else{
                wx.showToast({
                    title: res.message,
                    icon: 'none',
                    duration: 2000
                })
            }
        }, (err) => {
            wx.hideLoading()
            wx.showToast({
                title: err.data.message,
                icon: 'none',
                duration: 2000
            })
        })
    },

    // 确定修改或找回
    modifBtn:function(){
        var _this = this
        // 找回密码
        var { findPasswordPhoneVal, findPasswordCaptchaVal, findPasswordNewVal, findConfirmNewPasswordVal } = this.data
        var url = app.globalData.baseUrl + 'user/payCodeReset';
        var data = {
            phone: findPasswordPhoneVal,
            code: findPasswordCaptchaVal,
            password: findPasswordNewVal,
            repassword: findConfirmNewPasswordVal,
            token: app.globalData.token
        }
        wx.showLoading({
            title: '加载中',
        })
        app.wxPostRequest(url, data, (res) => {
            console.log(res)
            wx.hideLoading()
            if (res.code == 1000) {
                wx.showToast({
                    title: '修改成功',
                    icon: 'success',
                    duration: 2000
                })
                setTimeout(function () {
                    wx.navigateBack({
                        delta: 1
                    })
                }, 2000)
            }else{
                wx.showToast({
                    title: res.message,
                    icon: 'none',
                    duration: 2000
                })
            }
        }, (err) => {
            wx.hideLoading()

        })
    },
});
